package com.yang.paymentdemo.vo;

import lombok.Data;
import lombok.experimental.Accessors;

import java.util.HashMap;
import java.util.Map;

/**
 * @author yxc
 * @date 2022/1/21
 * vo包为value object，用于统一返回结果
 **/

@Data
@Accessors(chain = true)  //lombok注解，允许链式操作，会将所有set方法返回值设置为R对象
public class R {
    //响应码
    private Integer code;
    //响应消息
    private String message;
    private Map<String,Object> data = new HashMap<>();


    public static R ok(){
        R r = new R();
        //成功响应码
        r.setCode(0);
        r.setMessage("成功");
        return r;
    }

    public static R error(){
        R r = new R();
        //失败响应码
        r.setCode(-1);
        r.setMessage("失败");
        return r;
    }

    public R data(String key,Object value){
        this.data.put(key,value);
        return this;
    }


}
